package com.sunshine.wrongquestionset.activity.exercise

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.fragment.app.FragmentStatePagerAdapter
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.sunshine.wrongquestionset.room.entity.QuestionEntity
import kotlin.math.min

/**
 * @author sunshine
 * @date 2021/3/30
 */
class ExerciseScoreFragmentAdapter(
    fragmentActivity: FragmentActivity,
    private val list: List<QuestionEntity>?
): FragmentStateAdapter(fragmentActivity) {

    private val exerciseScoreCardFragment = ExerciseScoreCardFragment()

    override fun getItemCount(): Int {
        return list?.size?.plus(1) ?:1
    }

    override fun createFragment(position: Int): Fragment {
        return when (position) {
            //最后一页提交
            list!!.size -> {
                exerciseScoreCardFragment
            }

            else -> ExerciseScoreFragment.newInstance(position, list[position].id)
        }
    }

    fun getExerciseScoreCardFragment(): ExerciseScoreCardFragment {
        return exerciseScoreCardFragment
    }

}